package com.lxr0860.lxr0860production_test.itemactivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Window;
import android.widget.TextView;

import com.lxr0860.lxr0860production_test.R;
import com.lxr0860.lxr0860production_test.utils.Contants;
import com.lxr0860.lxr0860production_test.utils.RefreshViewUtils;
import com.lxr0860.lxr0860production_test.utils.ThreadPool;
import com.sdk.devicemanager.DEVICEcon;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.Method;

public class InfoActivity extends Activity {
    private TextView tvSysVersion;
    private int fingerLevel = 0;
    private int testPosition;
    private boolean destroy;
    private String icversion = "";
    private String[] split;

    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case Contants.DIALOG_POSITIVE:
                    Intent mIntent = new Intent();
                    Bundle bundle = new Bundle();
                    bundle.putBoolean("result", true);
                    mIntent.putExtras(bundle);
                    InfoActivity.this.setResult(Contants.TEST_ITEM_INFO, mIntent);
                    finish();
                    break;
                case Contants.DIALOG_NEGATIVE:
                    finish();
                    break;
            }
        }
    };
    private DEVICEcon mDevicEcon;

    private void init() {
        //获取上个Activity传过来的值
        testPosition = getIntent().getIntExtra("position", Contants.TEST_ZUZHUANG);
        tvSysVersion = (TextView) findViewById(R.id.tvSysVersion);
        mDevicEcon = new DEVICEcon(this);
        Log.e("tag",null);

        sendScanCommand();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_setting);
        init();
    }

    public String getJD() {
        String JD = null;
        try {
            Class e = Class.forName("android.os.SystemProperties");
//            Object invoker = e.newInstance();
            Method m = e.getMethod("get", new Class[]{String.class, String.class});
            Object result = m.invoke(null, new Object[]{"gsm.version.baseband", "no message"});
            JD = (String) result;
        } catch (Exception var6) {
            var6.printStackTrace();
        }
        return JD;
    }


    private void sendScanCommand() {
        tvSysVersion.setText("正在获取设备信息...");

        ThreadPool.getInstance().execute(new Runnable() {
            @Override
            public void run() {
                RefreshViewUtils.setText(InfoActivity.this, tvSysVersion,
                        "机器型号:" + Build.MODEL + "\n生  产  商:"
                                + Build.MANUFACTURER + "\n固件版本:" + Build.DISPLAY
//                                + "\n摄像头型号：" + getCameraInfo()
//                                + "jar包版本:" + mDevicEcon.getJarVersion()
                                + "\n基带版本号:" + getJD());

                //条码版本暂无接口

                try {
                    Thread.sleep(200);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                /*if (iccpowerOn == 0) {
                    final byte version[] = new byte[6];
                    final int ret = ICcon.getInstance().ICC_get_version(version);
                    if (ret == 0) {
                        icversion = version[0] + "." + version[1] + "." + version[2];
                        RefreshViewUtils.appendText(InfoActivity.this, tvSysVersion,
                                "\nIC卡固件版本:" + icversion);
                    } else
                        RefreshViewUtils.appendText(InfoActivity.this, tvSysVersion, "\n获取IC卡固件版本失败");
                } else {
                    RefreshViewUtils.appendText(InfoActivity.this, tvSysVersion, "\nIC卡上电失败");
                }

                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (icversion.equals("0.0.0")) {
                            ToastUtils.showMessage("IC固件版本错误");
                            return;
                        }
                    }
                });
                RefreshViewUtils.appendText(InfoActivity.this, tvSysVersion, "\n扫描头型号：" + Settings.System.getInt(InfoActivity.this.getContentResolver(),
                        "scanner_barcode_model", 0));

                 */
            }
        });
    }

    String str = "/sys/devices/platform/harewareinfo/hardwareinfo";

    /**
     * 获取摄像头信息
     *
     * @return
     */
    private String getCameraInfo() {

        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new FileReader(str));
            String str;
            String allstr = "";
            while ((str = reader.readLine()) != null) {
                if (str.length() > 2) {
                    allstr += str + "\n";
                }
            }
            split = allstr.split(" ");
            for (int i = 0; i < split.length; i++) {
                Log.e("split", "split" + i + ":" + split[i]);
            }
            return allstr;
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            try {
                reader.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        destroy = true;

    }

    private boolean isKeyDown = false;


}
